/*
 * flash.h
 *
 *  Created on: 2025年5月14日
 *      Author: chenm
 */

#ifndef FLASH_H_
#define FLASH_H_

#include "sdk_project_config.h"


#define FTFx_DPHRASE_SIZE  0x0010U

#define WRITE_BUFFER_SIZE         128u          /* Size of data source */

#define WRITE_BUFFER_SIZE_UPDATA         2048u          /* Size of data source */

#define EFM_SECTOR_VENDOR_A_DATA_NUM (31U)   // 璇婃柇鏁版嵁瀛樺偍鍖�

#define EFM_SECTOR_VENDOR_B_DATA_NUM (28U)   // 璇婃柇鏁版嵁瀛樺偍鍖�

#define SECTOR_SIZE                     (0x400UL)

#define SECTOR_ADDR(x)          (uint32_t)(SECTOR_SIZE * (x))

#define VENDOR_CRC32_DEFAULT_VALUE      (0xF0F0F0F0)

#define A_partion_address 		0x00008000

#define B_partion_address 		0x00024000

typedef struct VENDOR_DATA//新增结构体内容时，时刻关注字节对齐问题以及写flash大小必须为8的倍数
{
	uint32_t crc32;
    uint8_t mcu_upgrade_flag;		///< MCU的升级标志
    uint8_t screen_brightness;		///< 屏幕亮度

    uint8_t PN_VERSION0;
    uint8_t PN_VERSION1;
    uint8_t PN_VERSION2;
    uint8_t PN_VERSION3;
    uint8_t PN_VERSION4;
    uint8_t PN_VERSION5;
    uint8_t HARDWARE_VERSION0;
    uint8_t HARDWARE_VERSION1;
    uint8_t HARDWARE_VERSION2;
    uint8_t HARDWARE_VERSION3;
    uint8_t HARDWARE_VERSION4;
    uint8_t HARDWARE_VERSION5;
    uint8_t SOFTWARE_VERSION0;
    uint8_t SOFTWARE_VERSION1;
    uint8_t SOFTWARE_VERSION2;
    uint8_t SOFTWARE_VERSION3;
    uint8_t SOFTWARE_VERSION4;
    uint8_t host_ack_upgrade;
}ST_VENDOR_DATA;
extern void flash_init(void);
extern void flash_write(uint8_t * write_buffer,uint32_t address);
extern void flash_write_update(uint8_t * write_buffer,uint32_t address);
extern uint16_t flash_read_byte(volatile uint8_t * flashPtr,uint8_t *buffer, uint32_t length);
extern void vendor_data_save(void);
extern void vendor_factory_set(void);
extern bool vendor_data_A_load(void);
extern bool vendor_data_B_load(void);
#endif /* FLASH_H_ */
